home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / qdcursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-18  |  8.5 KB  |  313 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #define  NEED_EVENTS
  26.  
  27. #include <sys/types.h>
  28. #include "Ultrix2.0inc.h"
  29. #include <stdio.h>
  30. #include "X.h"        /* for "Device" */
  31. #include "Xproto.h"
  32.  
  33. #include "scrnintstr.h"
  34. #include "cursorstr.h"
  35. #include "input.h"
  36.  
  37. #include <vaxuba/qdreg.h>
  38. #include <vaxuba/qdioctl.h>
  39. #include <vaxuba/qevent.h>
  40. #include <vaxuba/qduser.h>
  41. #include "libtl/tlsg.h"
  42. #include "libtl/tl.h"
  43.  
  44. #include "regionstr.h"
  45.  
  46. extern int  qdGetMotionEvents();
  47. extern void qdChangePointerControl(), qdChangeKeyboardControl(), qdBell();
  48.  
  49. /* ifdef Vaxstar */
  50. extern short *DMAdev_reg;
  51. extern int    Nplanes;
  52. extern int    Vaxstar;
  53. /* endif Vaxstar */
  54.  
  55. /*
  56.  * shorthand to a struct in qdmap
  57.  */
  58. extern vsCursor *    mouse;
  59. extern vsBox *        mbox;        /* limits for unreported motion */
  60.  
  61. extern int        fd_qdss;
  62.  
  63. /*
  64. Bool qdRealizeCursor(), qdUnrealizeCursor(), qdDisplayCursor();
  65. Bool qdSetCursorPosition();
  66. void qdCursorLimits();
  67. void qdPointerNonInterestBox();
  68. void qdConstrainCursor();
  69.  */
  70.  
  71. int hotX, hotY; /* "current" position */
  72.  
  73. Bool
  74. qdSetCursorPosition( pScr, newx, newy, generateEvent)
  75.     ScreenPtr        pScr;        /* NOT USED */
  76.     unsigned int    newx;
  77.     unsigned int    newy;
  78.     Bool        generateEvent;
  79. {
  80.     vsCursor    cursor;
  81.     xEvent      motion;
  82.     
  83.     extern DevicePtr    qdPointer;
  84.     extern vsEventQueue *queue;          /* shorthand to a struct in qdmap */
  85.     extern int        lastEventTime;
  86.  
  87.     if (generateEvent)
  88.     {
  89.         if (queue->head != queue->tail)
  90.             ProcessInputEvents();
  91.         motion.u.keyButtonPointer.rootX = newx;
  92.         motion.u.keyButtonPointer.rootY = newy;
  93.         motion.u.keyButtonPointer.time = lastEventTime;
  94.         motion.u.u.type = MotionNotify;
  95.         (* qdPointer->processInputProc)( &motion, qdPointer, 1);
  96.     }
  97.     cursor.x = newx - hotX;
  98.     cursor.y = newy - hotY;
  99.     if ( ioctl(fd_qdss, QD_POSCURSOR, &cursor) < 0)
  100.     {
  101.     ErrorF( "error warping cursor\n");
  102.     return FALSE;
  103.     }
  104.  
  105.     return TRUE;
  106. }
  107.  
  108. Bool
  109. qdDisplayCursor( pScr, pCurs)
  110.     ScreenPtr    pScr;
  111.     CursorPtr    pCurs;
  112. {
  113.     int x, y;
  114. /* ifdef Vaxstar */
  115.     u_short red,green,blue;
  116.     u_short color;
  117.     short * vdac_sav;
  118.     short * eight_planes;
  119. /* endif         */
  120.  
  121.     xColorItem    colors[2];
  122.     extern struct dga   *Dga;
  123.     register struct dga   *dga = Dga;    /* required to be register */
  124.  
  125.  
  126.     /*
  127.      * load cursor colors
  128.      */
  129.  
  130.     if (!Vaxstar)
  131.     {
  132.         colors[0].pixel = 254;
  133.         colors[1].pixel = 255;
  134.         colors[0].flags = DoRed|DoGreen|DoBlue;
  135.         colors[0].red = pCurs->backRed;
  136.         colors[0].green = pCurs->backGreen;
  137.         colors[0].blue = pCurs->backBlue;
  138.         colors[1].flags = DoRed|DoGreen|DoBlue;
  139.         colors[1].red = pCurs->foreRed;
  140.         colors[1].green = pCurs->foreGreen;
  141.         colors[1].blue = pCurs->foreBlue;
  142.  
  143.         dga->csr &= ~CURS_ENB;
  144.         qdStoreColors( NULL, 2, colors);
  145.     }
  146.     else  /*Vaxstar*/
  147.     {
  148.         if (Nplanes != 8)  /*The VDAC*/
  149.         {
  150.             /* load the background color */
  151.             blue = (pCurs->backBlue >> 12);
  152.             red = (pCurs->backRed >> 12);
  153.             green = (pCurs->backGreen >> 12);
  154.             color = (green << 8);
  155.             color |= (blue << 4);
  156.             color |= red;
  157.             vdac_sav = DMAdev_reg;
  158.             vdac_sav += 33; /* See Page 9 of the VDAC func spec - VKB */
  159.             *vdac_sav++ = color;
  160.             /* load the foreground color */
  161.             blue = (pCurs->foreBlue >> 12);
  162.             red = (pCurs->foreRed >> 12);
  163.             green = (pCurs->foreGreen >> 12);
  164.             color = (green << 8);
  165.             color |= (blue << 4);
  166.             color |= red;
  167.             vdac_sav++;
  168.             *vdac_sav = color;
  169.         }
  170.         else                /*The Brooktree*/
  171.         {
  172.             /* load the background color */
  173.             eight_planes = DMAdev_reg;
  174.             *eight_planes = 1;
  175.             eight_planes += 3;
  176.             *eight_planes = (pCurs->backRed >> 8);
  177.             *eight_planes = (pCurs->backGreen >> 8);
  178.             *eight_planes = (pCurs->backBlue >> 8);
  179.             /* load the foreground color */
  180.             eight_planes = DMAdev_reg;
  181.             *eight_planes = 3;
  182.             eight_planes += 3;
  183.             *eight_planes = (pCurs->foreRed >> 8);
  184.             *eight_planes = (pCurs->foreGreen >> 8);
  185.             *eight_planes = (pCurs->foreBlue >> 8);
  186.         }
  187.     }
  188.  
  189.     ioctl( fd_qdss, QD_WTCURSOR, (short *)pCurs->devPriv[ pScr->myNum]);
  190.  
  191.     if (!Vaxstar)
  192.     dga->csr |= CURS_ENB;
  193.  
  194. #ifdef X11R4
  195.     if ((hotX != pCurs->bits->xhot) || (hotY != pCurs->bits->yhot))
  196. #else
  197.     if ((hotX != pCurs->xhot) || (hotY != pCurs->yhot))
  198. #endif
  199.     {
  200.         x = mouse->x + hotX;
  201.         y = mouse->y + hotY;
  202. #ifdef X11R4
  203.         hotX = pCurs->bits->xhot;
  204.         hotY = pCurs->bits->yhot;
  205. #else
  206.         hotX = pCurs->xhot;
  207.         hotY = pCurs->yhot;
  208. #endif
  209.         qdSetCursorPosition(pScr, x, y, FALSE);
  210.     }
  211. }
  212.  
  213. void
  214. qdPointerNonInterestBox( pScr, pBox)
  215.     ScreenPtr    pScr;
  216.     BoxPtr    pBox;
  217. {
  218.     mbox->left = pBox->x1;
  219.     mbox->right = pBox->x2;
  220.     mbox->top = pBox->y1;
  221.     mbox->bottom = pBox->y2;
  222. }
  223.  
  224. /*
  225.  * Let DIX do this, as qdss driver is incapable of constraining the sprite
  226.  * to any bounds other than the physical screen.
  227.  */
  228. void
  229. qdConstrainCursor( pScr, pBox)
  230.     ScreenPtr    pScr;
  231.     BoxPtr    pBox;
  232. {
  233. }
  234.  
  235. /*
  236.  * Qd cursor top-left corner cannot go to negative coordinates
  237.  * (at least the driver thinks not).
  238.  */
  239. void
  240. qdCursorLimits( pScr, pCurs, pHotBox, pTopLeftBox)
  241.     ScreenPtr    pScr;
  242.     CursorPtr    pCurs;
  243.     BoxPtr    pHotBox;
  244.     BoxPtr    pTopLeftBox;    /* return value */
  245. {
  246. #ifdef X11R4
  247.     pTopLeftBox->x1 = max( pHotBox->x1 - pCurs->bits->xhot, 0);
  248.     pTopLeftBox->y1 = max( pHotBox->y1 - pCurs->bits->yhot, 0);
  249.     pTopLeftBox->x2 = min( pHotBox->x2 - pCurs->bits->xhot, 1023);
  250.     pTopLeftBox->y2 = min( pHotBox->y2 - pCurs->bits->yhot, 863);
  251. #else
  252.     pTopLeftBox->x1 = max( pHotBox->x1 - pCurs->xhot, 0);
  253.     pTopLeftBox->y1 = max( pHotBox->y1 - pCurs->yhot, 0);
  254.     pTopLeftBox->x2 = min( pHotBox->x2 - pCurs->xhot, 1023);
  255.     pTopLeftBox->y2 = min( pHotBox->y2 - pCurs->yhot, 863);
  256. #endif
  257. }
  258.  
  259. Bool
  260. qdRealizeCursor( pScr, pCurs)
  261.     ScreenPtr    pScr;
  262.     CursorPtr    pCurs;    /* a SERVER-DEPENDENT cursor */
  263. {
  264.     register short     *pHardSrc, *pHardMsk;    /* qdss-defined */
  265.     register int     *pServSrc, *pServMsk;    /* server-defined
  266.                    assumes serverscanlinepad = sizeof(int) */
  267.     register int    i;
  268. #ifdef X11R4
  269.     unsigned int widthmask = (1<<pCurs->bits->width)-1;
  270. #else
  271.     unsigned int widthmask = (1<<pCurs->width)-1;
  272. #endif
  273.  
  274.     pCurs->devPriv[pScr->myNum] = (pointer)Xalloc( 32*sizeof(short));
  275.     bzero((char *)pCurs->devPriv[pScr->myNum], 32*sizeof(short));
  276.  
  277.     /*
  278.      * Munge the SERVER-DEPENDENT, device-independent cursor bits into
  279.      * what the device wants.
  280.      * Assumes that the DIX cursor format is padded to int boundaries.
  281.      * Mask bits first, then source.
  282.      */
  283. #ifdef X11R4
  284.     i = pCurs->bits->height;
  285. #else
  286.     i = pCurs->height;
  287. #endif
  288.     if (i > 16) i = 16;
  289.     for (
  290.           pHardMsk = &((short *)pCurs->devPriv[ pScr->myNum])[0],
  291.           pHardSrc = &((short *)pCurs->devPriv[ pScr->myNum])[16],
  292. #ifdef X11R4
  293.           pServMsk = (int *)pCurs->bits->mask,
  294.           pServSrc = (int *)pCurs->bits->source;
  295. #else
  296.           pServMsk = (int *)pCurs->mask,
  297.           pServSrc = (int *)pCurs->source;
  298. #endif
  299.       --i >= 0; ) {
  300.     *pHardMsk++ = *pServMsk++ & widthmask; /* clip to cursor width */
  301.     *pHardSrc++ = *pServSrc++ & widthmask; /* clip to cursor width */
  302.     }
  303.     return TRUE;
  304. }
  305.  
  306. Bool
  307. qdUnrealizeCursor( pScr, pCurs)
  308.     ScreenPtr    pScr;
  309.     CursorPtr    pCurs;
  310. {
  311.     Xfree( pCurs->devPriv[ pScr->myNum]);
  312. }
  313.